# TODO: Add parsers for each item on template checks
from aiogram import Router
from aiogram.fsm.context import FSMContext
from aiogram.types import Message
from fluent.runtime import FluentLocalization

from recruit_bot.dialogs import created_template_cv
from recruit_bot.handlers.state import TemplateCVState

router = Router()


@router.message(TemplateCVState.info_cv)
async def set_user_info(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    await state.update_data(info=message.text)
    await state.set_state(TemplateCVState.position_cv)
    await created_template_cv.send_position(message, l10n)


@router.message(TemplateCVState.position_cv)
async def set_position(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    await state.update_data(position=message.text)
    await state.set_state(TemplateCVState.salary_cv)
    await created_template_cv.send_salary(message, l10n)


@router.message(TemplateCVState.salary_cv)
async def set_salary(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    if message.text != '/skip':
        await state.update_data(salary=message.text)
    await state.set_state(TemplateCVState.contact_cv)
    await created_template_cv.send_contact(message, l10n)


@router.message(TemplateCVState.contact_cv)
async def set_contact(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    await state.update_data(contact=message.text)
    await state.set_state(TemplateCVState.work_cv)
    await created_template_cv.send_work(message, l10n)


@router.message(TemplateCVState.work_cv)
async def set_work(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    if message.text != '/skip':
        await state.update_data(work=message.text)
    await state.set_state(TemplateCVState.skills_cv)
    await created_template_cv.send_skills(message, l10n)


@router.message(TemplateCVState.skills_cv)
async def set_skills(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    await state.update_data(skills=message.text)
    await state.set_state(TemplateCVState.about_cv)
    await created_template_cv.send_about_us(message, l10n)


@router.message(TemplateCVState.about_cv)
async def set_about(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    if message.text != '/skip':
        await state.update_data(about=message.text)
    await state.set_state(TemplateCVState.education_cv)
    await created_template_cv.send_education(message, l10n)


@router.message(TemplateCVState.education_cv)
async def set_education(
        message: Message,
        l10n: FluentLocalization,
        state: FSMContext
) -> None:
    # TODO: Add the following processing
    await state.update_data(education=message.text)
    await created_template_cv.send_cv(message, l10n, await state.get_data())
